package com.zzh.takeoutapp.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.config.UrlConfig;
import com.zzh.takeoutapp.utils.CountTimerUtlis;
import com.zzh.takeoutapp.utils.SPUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author zzh
 * @Name:
 * @Description:
 * @date
 * @time
 * @copyright
 */
public class SplashActivity extends AppCompatActivity {
    @Bind(R.id.in_splash)
    ImageView in_splash;
    @Bind(R.id.bnt_splash)
    Button bnt_splash;
    private CountTimerUtlis countTimerUtlis;
    private long millisInFuture = 2000;
    private long countDownInterval = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏
        if (Build.VERSION.SDK_INT >= 14) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        initComponent();
    }

    public void initComponent() {
        countTimerUtlis = new CountTimerUtlis(
                millisInFuture, countDownInterval, bnt_splash, R.string.app_name, new CountTimerUtlis.Call() {
            @Override
            public void END() {
                bnt_splash.setEnabled(true);
                start_Activity();
                countTimerUtlis.cancel();
            }
        });
        countTimerUtlis.start();
    }

    private void start_Activity() {
        //if (SPUtils.getBoolean(SplashActivity.this, UrlConfig.ISFIRSTSTR, false) == false) {
          //  start_Activity(new Intent(SplashActivity.this, LoginActivity.class));
        //} else {
            start_Activity(new Intent(SplashActivity.this, MainActivity.class));
       // }
        finish_Activity();
    }

    public void start_Activity(Intent intent) {
        startActivity(intent);
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }

    public void finish_Activity() {
        finish();
        overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }


    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        countTimerUtlis.cancel();
    }
}
